from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 初始化WebDriver，这里以Chrome为例
driver = webdriver.Chrome()

# 打开目标网页
driver.get("http://valser.org/reg/2024/index/identity.html")

# 等待页面加载完成
wait = WebDriverWait(driver, 10)

# 填写手机号，这里需要替换成有效的手机号码
phone_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#app [placeholder='请输入手机号码']")))
phone_input.send_keys("18801321911")

# 选择手机验证码选项
checktype_radio = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#app [value='1']")))
checktype_radio.click()

# 获取并填写验证码
# 这里需要实现验证码的自动识别和输入，通常需要借助图像识别技术
# 以下代码仅为示意，实际应用中需要替换成有效的验证码识别逻辑
captcha_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#app .captcha-input")))
captcha_input.send_keys("自动识别的验证码")  # 替换成实际识别的验证码

# 点击获取短信验证码
get_phone_verify_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#app .getverify")))
get_phone_verify_button.click()

# 等待短信验证码发送并填写
# 这里需要实现短信的接收和解析，通常需要借助短信服务API
# 以下代码仅为示意，实际应用中需要替换成有效的短信处理逻辑
sms_code = "收到的短信验证码"  # 替换成实际收到的短信验证码
phone_code_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#app [placeholder='手机短信验证码']")))
phone_code_input.send_keys(sms_code)

# 提交表单
submit_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#app .submit-btn")))
submit_button.click()

# 等待结果页面加载
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#app .alert-info")))

# 关闭WebDriver
driver.quit()